ContextHelper::is_in_isset_or_empty(): add basic tests#2725
Conversation
| $obj?->key_exists( 'key', /* testNullsafeObjectMethod */ $array ); | ||
| MyClass::array_key_exists( 'key', /* testStaticMethod */ $array ); | ||
| key_exists( 'key', my_function( /* testNestedFunctionCall */ $array ) ); | ||
|
|
There was a problem hiding this comment.
How about the negative test of just bare $value too?
There was a problem hiding this comment.
Thanks for the review, @GaryJones. I added the bare $value negative test you suggested. I also added a nested valid function call test similar to the one you suggested in the review of #2721 and renamed testNestedFunctionCall to testNestedNonTargetFunctionCall to better contrast with the new positive case.
| $obj?->key_exists( 'key', /* testNullsafeObjectMethod */ $array ); | ||
| MyClass::array_key_exists( 'key', /* testStaticMethod */ $array ); | ||
| key_exists( 'key', my_function( /* testNestedNonTargetFunctionCall */ $array ) ); | ||
|
|
There was a problem hiding this comment.
How about adding these ("no false positives") tests too ?
Foo::isset();
Some\Ns\empty();
And maybe one or two variations, don't need to be silly comprehensive as the tokenizer wouldn't tokenize the above as T_ISSET/T_EMPTY (which is why this isn't specifically tested in PHPCSUtils and all the more reason we should have a few of these tests here).
There was a problem hiding this comment.
I thought about it, but then opted not to add the tests precisely because PHPCS doesn't tokenize the above as T_ISSET/T_EMPTY. That said, those tests will not hurt, and I added a new commit with them.
Description
In preparation for supporting PHPCS 4.0, this PR adds unit tests for the
ContextHelper::is_in_isset_or_empty()method.Suggested changelog entry
N/A